import { addUser, postUserListData, type IUser } from '@/service/main/system/user'
import { defineStore } from 'pinia'

interface ISystemState {
  userList: Array<{
    id: number
    name: string
    realName: string
    cellPhone: number
    enable: number
    departmentId: number
    roleId: number
    createAt: string
    updateAt: string
  }>
  userListTotal: number
}

const useSystemStore = defineStore('system', {
  state: (): ISystemState => {
    return {
      userList: [],
      userListTotal: 0
    }
  },
  actions: {
    async postUserListAction(info: { size: number; offset: number }) {
      console.log('info: ', info)
      // const result = await postUserListDataMock(info)
      // const { totalCount, list } = result.data
      // this.userList = list
      // this.userListTotal = totalCount

      // 接口
      const { data } = await postUserListData()
      console.log('data: ', data)
      this.userList = data.list
      this.userListTotal = data.total
    },
    async addUserAction(user: IUser) {
      const res = await addUser(user)
      if (res.code === 0) {
        this.postUserListAction({ size: 10, offset: 0 })
      }
    }
  }
})

export default useSystemStore
